package com.ruibang.glass.equipment.service.impl;

import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruibang.glass.equipment.dto.SelectDTO;
import com.ruibang.glass.equipment.entity.device.ProductLine;
import com.ruibang.glass.equipment.mapper.device.ProductLineMapper;
import com.ruibang.glass.equipment.service.ProductLineService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * @Author: songJinKang
 * @CreateTime: 2023-11-15  19:10
 * @Description: TODO
 * @Version: 1.0
 */
@Slf4j
@Service
public class ProductLineImpl extends ServiceImpl<ProductLineMapper, ProductLine> implements ProductLineService {

    /**
     * 产品线
     * @param workshopId
     * @return
     */
    @Override
    public List<ProductLine> getProductLineList(String workshopId) {
        if (StringUtils.isNotBlank(workshopId)) {
            return lambdaQuery().eq(ProductLine::getWorkshopId, workshopId).list();
        }
        return lambdaQuery().list();
    }

    /**
     * 下拉框
     * @param id
     * @return
     */
    @Override
    public List<SelectDTO> getSelectList(String id) {
        List<ProductLine> productLineList = null;
        if (StringUtils.isNotBlank(id)) {
            productLineList = baseMapper.selectList(Wrappers.<ProductLine>lambdaQuery().eq(ProductLine::getWorkshopId, id));
        } else {
            productLineList = this.list();
        }
        if (CollectionUtils.isNotEmpty(productLineList)) {
            List<SelectDTO> selectDTOList = new ArrayList<>();
            for (ProductLine productLine : productLineList) {
                SelectDTO selectDTO = new SelectDTO();
                selectDTO.setLabel(productLine.getProductLineName());
                selectDTO.setValue(productLine.getProductLineId());
                selectDTOList.add(selectDTO);
            }
            return selectDTOList;
        }
        return Collections.emptyList();
    }
}
